Adds fill in front of s until it is width characters long, so text lines up: string_pad_left("7", 3, "0") is "007" and string_pad_left("42", 5, " ") is " 42". Only the first character of fill is used. Text that is already long enough comes back as it was.
string_pad_left(s, width, fill) -> string| Name | Type |
|---|---|
s | string |
width | int |
fill | string |
string
Adds fill in front of s until the text is width characters long, so text lines up. Use it for scores, clocks and tables.
var score = string_pad_left("42", 5, " ");
var code = string_pad_left("7", 3, "0");score is " 42" (three spaces and 42) and code is "007".
fill is used: string_pad_left("7", 4, "xy") is "xxx7". An empty fill pads with spaces.width characters or longer comes back as it was. It is never cut down to width.width of 0 or less changes nothing.string_digits.One pass over the text, at most as long as a string can be.
A string has a fixed amount of room - your project's Longest string setting (32 characters unless you changed it). If the padded result would not fit, it is quietly cut off at the end, no error, and the game carries on. A width of 0 or less, or text already width long, changes nothing. An empty fill pads with spaces. For a whole number written with zeros in front, string_digits does it in one step.